package com.ruoyi.web.controller.bargain;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bargain.domain.BargainAwards;
import com.ruoyi.bargain.service.IBargainAwardsService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 领取奖品记录 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-07
 */
@Controller
@RequestMapping("/bargain/bargainAwards")
public class BargainAwardsController extends BaseController
{
    private String prefix = "bargain/bargainAwards";
	
	@Autowired
	private IBargainAwardsService bargainAwardsService;
	
	@RequiresPermissions("bargain:bargainAwards:view")
	@GetMapping()
	public String bargainAwards()
	{
	    return prefix + "/bargainAwards";
	}
	
	/**
	 * 查询领取奖品记录列表
	 */
	@RequiresPermissions("bargain:bargainAwards:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BargainAwards bargainAwards)
	{
		startPage();
        List<BargainAwards> list = bargainAwardsService.selectBargainAwardsList(bargainAwards);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出领取奖品记录列表
	 */
	@RequiresPermissions("bargain:bargainAwards:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BargainAwards bargainAwards)
    {
    	List<BargainAwards> list = bargainAwardsService.selectBargainAwardsList(bargainAwards);
        ExcelUtil<BargainAwards> util = new ExcelUtil<BargainAwards>(BargainAwards.class);
        return util.exportExcel(list, "bargainAwards");
    }
	
	/**
	 * 新增领取奖品记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存领取奖品记录
	 */
	@RequiresPermissions("bargain:bargainAwards:add")
	@Log(title = "领取奖品记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BargainAwards bargainAwards)
	{		
		return toAjax(bargainAwardsService.insertBargainAwards(bargainAwards));
	}

	/**
	 * 修改领取奖品记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		BargainAwards bargainAwards = bargainAwardsService.selectBargainAwardsById(id);
		mmap.put("bargainAwards", bargainAwards);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存领取奖品记录
	 */
	@RequiresPermissions("bargain:bargainAwards:edit")
	@Log(title = "领取奖品记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BargainAwards bargainAwards)
	{		
		return toAjax(bargainAwardsService.updateBargainAwards(bargainAwards));
	}
	
	/**
	 * 删除领取奖品记录
	 */
	@RequiresPermissions("bargain:bargainAwards:remove")
	@Log(title = "领取奖品记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bargainAwardsService.deleteBargainAwardsByIds(ids));
	}
	
}
